package com.cc.controller;

import com.cc.entity.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cc.entity.Employees;
import com.cc.service.IEmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 员工登录表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2024-12-09
 */
@RestController
@RequestMapping("/employees")
@Tag(name = "员工登录表",description = "员工登录表接口")
public class EmployeesController {
    @Autowired
    private IEmployeesService employeeService;

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    // 获取分页数据
    @GetMapping("/page")
    @Operation(summary = "获取员工分页数据",description = "分页查询员工信息")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200",description = "请求成功"),
            @ApiResponse(responseCode = "300",description = "请求参数错误")
    })
    public PageResult<Employees> getEmployeePage(
            @Parameter(name = "pageNum",description = "当前页码",required = true) int pageNum,
            @Parameter(name = "pageSize",description = "每页条数",required = false)
        @RequestParam(value = "pageSize",defaultValue = "5") // 默认每页显示5条数据
        int pageSize) {
        Page page = new Page(pageNum, pageSize);
        return employeeService.getPage(page);
    }

    // 通过员工Id获取员工信息
    @GetMapping("/{id}")
    public Employees getEmployeeById(@PathVariable Long id) {
        return employeeService.getById(id);
    }

    // 新增员工
    @PostMapping
    public boolean addEmployee(@RequestBody Employees employee) {
        return employeeService.save(employee);
    }

    // 修改员工信息
    @PutMapping
    public boolean updateEmployee(@RequestBody Employees employee) {
        return employeeService.updateById(employee);
    }

    // 删除员工
    @DeleteMapping("/{id}")
    public boolean deleteEmployee(@PathVariable Long id) {
        return employeeService.removeById(id);
    }
}